package com.starleague.battletech.hexagonal.jpa.appengine;

import com.starleague.battletech.game.IBattletechGame;
import com.starleague.battletech.game.jpa.appengine.BattletechGameGae;
import com.starleague.battletech.hexagonal.BattletechHexTerrainType;
import com.starleague.battletech.hexagonal.IBattletechHex;
import com.starleague.battletech.hexagonal.IBattletechHexGrid;
import com.starleague.battletech.hexagonal.IBattletechHexGridFactory;
import com.starleague.hexagonal.HexException;
import com.starleague.hexagonal.IHexCoordinate;

public class BattletechHexGridGaeFactory
        implements IBattletechHexGridFactory
{
    @Override
    public BattletechHexGridGae createHexGrid(IBattletechGame game,
                                              int minGridX,
                                              int minGridY,
                                              int numHexesX,
                                              int numHexesY) throws HexException
    {
        BattletechHexGridGae hexGrid = new BattletechHexGridGae(((BattletechGameGae) game),
                                                                minGridX,
                                                                minGridY,
                                                                numHexesX,
                                                                numHexesY);
        if (game != null)
            ((BattletechGameGae) game).setHexGrid(hexGrid);
        return hexGrid;
    }

    @Override
    public BattletechHexGae createHex(IBattletechHexGrid hexGrid,
                                      IHexCoordinate hexCoordinate,
                                      int elevation) throws HexException
    {
        BattletechHexGae hex = new BattletechHexGae(((BattletechHexGridGae) hexGrid), hexCoordinate, elevation);
        ((BattletechHexGridGae) hexGrid).addHex(hex);
        return hex;
    }

    @Override
    public BattletechHexTerrainGae createHexTerrain(IBattletechHex hex,
                                                    BattletechHexTerrainType hexTerrainType,
                                                    int level) throws HexException
    {
        BattletechHexTerrainGae hexTerrain = new BattletechHexTerrainGae(((BattletechHexGae) hex),
                                                                         hexTerrainType,
                                                                         level);
        ((BattletechHexGae) hex).getHexTerrainList().add(hexTerrain);
        return hexTerrain;
    }
}
